#include "yhsocket.h"

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>


int main(int argc, char *argv[])
{
    if (argc != 2) {
        printf("usage: %s <domain service path>\n", argv[0]);
        return 1;
    }
    int fd = unix_domain_server_udp(argv[1]);
    if (fd < 0) {
        printf("unix_domain_listen_udp error %d: %s\n", errno, strerror(errno));
        return 1;
    }

    int ret;
    char buff[1024*10];

    while (1) {
        ret = recv(fd, buff, sizeof(buff), 0);
        if (ret > 0) {
            printf("recv %d \"%s\"\n", ret, buff);
        } else if (ret == 0) {
            printf("recv 0\n");
        } else {
            printf("recv %d error %d: %s\n", ret, errno, strerror(errno));
        }
    }

    return 0;
}
